package com.ai.smlcore.service.impl;

import java.util.Map;

import com.ai.frame.bean.InputObject;
import com.ai.frame.bean.OutputObject;
import com.ai.frame.logger.Logger;
import com.ai.frame.logger.LoggerFactory;
import com.ai.smlcore.service.IFlowDictionaryService;
import com.ai.smlcore.util.BusinessException;
import com.ai.smlcore.util.StringUtil;

public class FlowDictionaryServiceImpl extends BaseServiceImpl implements IFlowDictionaryService {
	private static final Logger logger = LoggerFactory.getServiceLog(FlowDictionaryServiceImpl.class);
	//根据应用范围检索字典
	public void queryDictionaryListByRange(InputObject inputObject, OutputObject outputObject) throws BusinessException {
		//检查应用范围是否有值，当为空的时候不执行检索
		if(StringUtil.isEmpty(inputObject.getParams().get("appliedRange"))){
			throw new BusinessException("参数配置错误");
		}
		
		inputObject.setService("flowDictionaryService");
		inputObject.setMethod("queryDictionaryListByRange");
		getSmlRemoteSV().execute(inputObject, outputObject);
	}
	//根据应用范围检索字典
	public void queryDictionaryList(InputObject inputObject, OutputObject outputObject) throws BusinessException {
		inputObject.setService("flowDictionaryService");
		inputObject.setMethod("queryDictionaryList");
		getSmlRemoteSV().execute(inputObject, outputObject);
	}

	@Override
	public void insertDictionary(InputObject inputObject, OutputObject outputObject) throws BusinessException {
		Map<String, String> map = inputObject.getParams();
		if(StringUtil.isEmpty(map.get("dicName"))){
			logger.info("insertDictionary", "缺少参数dicName");
			throw new BusinessException("新增失败，缺少参数dicName");
		}
		if(StringUtil.isEmpty(map.get("dicValue"))){
			logger.info("insertDictionary", "缺少参数dicValue");
			throw new BusinessException("新增失败，缺少参数dicValue");
		}
		if(StringUtil.isEmpty(map.get("appliedRange"))){
			logger.info("insertDictionary", "缺少参数appliedRange");
			throw new BusinessException("新增失败，缺少参数appliedRange");
		}
		inputObject.setService("flowDictionaryService");
		inputObject.setMethod("insertDictionary");
		getSmlRemoteSV().execute(inputObject, outputObject);
	}

	@Override
	public void updateDictionary(InputObject inputObject, OutputObject outputObject) throws BusinessException {
		Map<String, String> map = inputObject.getParams();
		if(StringUtil.isEmpty(map.get("dicValue"))){
			logger.info("updateDictionary", "缺少参数dicValue");
			throw new BusinessException("修改失败，缺少参数dicValue");
		}
		if(StringUtil.isEmpty(map.get("appliedRange"))){
			logger.info("updateDictionary", "缺少参数appliedRange");
			throw new BusinessException("修改失败，缺少参数appliedRange");
		}
		inputObject.setService("flowDictionaryService");
		inputObject.setMethod("updateDictionary");
		getSmlRemoteSV().execute(inputObject, outputObject);
	}

	@Override
	public void deleteDictionary(InputObject inputObject, OutputObject outputObject) throws BusinessException {
		Map<String, String> map = inputObject.getParams();
		if(StringUtil.isEmpty(map.get("dicValue"))){
			logger.info("deleteDictionary", "缺少参数dicValue");
			throw new BusinessException("删除失败，缺少参数dicValue");
		}
		if(StringUtil.isEmpty(map.get("appliedRange"))){
			logger.info("deleteDictionary", "缺少参数appliedRange");
			throw new BusinessException("删除失败，缺少参数appliedRange");
		}
		inputObject.setService("flowDictionaryService");
		inputObject.setMethod("deleteDictionary");
		getSmlRemoteSV().execute(inputObject, outputObject);
	}
}
